﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.IdentityModel.Tokens.Jwt;
using T.ApiResults;
using T.Vehicleservice.Domain.Dtos;
using T.Vehicleservice.Domain.T.MaintenanceRecord.Model;
using T.Vehicleservice.Read.API.Application.Command.MaintenancesRecordCommand;

namespace T.Vehicleservice.Read.API.Controllers
{
    /// <summary>
    /// 显示保养信息控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaintenanceRecordsController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator _mediator;
        public MaintenanceRecordsController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 显示保养信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDto<MaintenancesRecord>>> GetMaintenancesRecordAll([FromQuery] MaintenanceRecordListCommand command)
        {
            ApiResult<PageDto<MaintenancesRecord>> result = new ApiResult<PageDto<MaintenancesRecord>>();
            try
            {
                command.CompanyID = HttpContext.User.FindFirst(JwtRegisteredClaimNames.Sid)?.Value;//公司ID
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
